using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Info.Basic;
using EntLibEC.Biz;
using EntLibEC.Biz.Basic;
using EntLibEC.Cmn;

namespace EntLibEC.View.Basic
{ 
	/// <summary>
	/// Summary description for SetNotShowTop10.
	/// </summary>
	public partial class SetNotShowTop10 : PageBase
	{
		protected EntLibEC.View.Cmn.StockProduct ucProduct ;
		protected EntLibEC.View.Cmn.Menu Menu1;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{				
				bindGrid();
			}
			
		}

		private void bindGrid()
		{
		    Hashtable ht = new Hashtable();

			if (ucProduct.ProductSysNo != AppConst.IntNull)
				ht.Add("ProductSysNo" , ucProduct.ProductSysNo);
			

			DataSet ds = ProductNotShowTop10Manager.GetInstance().GetNotShowTop10List(ht);

			base.SetDataGridPage(ds, dgNotShowTop10);
			dgNotShowTop10.DataSource = ds ;
			dgNotShowTop10.DataBind();
			Assert(lblMessage, (ds.Tables[0].Rows.Count).ToString() + " record(s)!", 1);
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.dgNotShowTop10.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgNotShowTop10_ItemCommand);
			this.dgNotShowTop10.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dgNotShowTop10_PageIndexChanged);

		}
		#endregion

		protected void btnAdd_Click(object sender, System.EventArgs e)
		{
			if (ProductNotShowTop10Manager.GetInstance().isHasItem(ucProduct.ProductSysNo))
			{
			    Assert(lblMessage,"Already exist in DataBase" , -1);
				return ;
			}
			if ( !base.CheckAccess((int)AppEnum.Privilege.NotShowTop10, false, lblMessage) )
				return;
			if (ucProduct.ProductSysNo == AppConst.IntNull)
			{
				Assert(lblMessage, "Please input product!", -1);
				return ;
			}
			try
			{
				ProductNotShowTop10Info oInfo = new ProductNotShowTop10Info();
				oInfo.ProductSysNo = ucProduct.ProductSysNo;
				oInfo.CreateTime = DateTime.Now ;
				SessionInfo xInfo= (SessionInfo)Session["SessionInfo"];
				if (xInfo != null && xInfo.User != null)				
					oInfo.CreateUserSysNo = xInfo.User.SysNo;
				ProductNotShowTop10Manager.GetInstance().insert(oInfo);
				ucProduct.ProductSysNo = AppConst.IntNull;
				bindGrid();
			}			
			catch
			{
			    Assert(lblMessage, "Add New Item Error!!", -1);
			}
			
		}

		protected void btnSearch_Click(object sender, System.EventArgs e)
		{
			bindGrid();
		}

		private void dgNotShowTop10_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if ( !base.CheckAccess((int)AppEnum.Privilege.NotShowTop10, false, lblMessage) )
				return;

			if ( e.CommandName == "delete" )
			{
				try
				{
					ProductNotShowTop10Manager.GetInstance().delete((int)dgNotShowTop10.DataKeys[(int)e.Item.ItemIndex]);
					bindGrid();
				}
				catch
				{
				    Assert(lblMessage, "Delete Item Error!!", -1);
				}
			}
		}

		private void dgNotShowTop10_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			dgNotShowTop10.CurrentPageIndex = e.NewPageIndex;
			bindGrid();
		}
	}
}
